{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据的读取加载\n",
    "    pandas中的dtype类型\n",
    "        int\n",
    "        float\n",
    "        datatime\n",
    "        bool\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas\n",
    "food_info = pandas.read_csv(\"food_info.csv\")\n",
    "\n",
    "# 数据的读取\n",
    "# 查看pands中的数据的前n行 dataframe.head(n)\n",
    "food_info.head(10) # 输出前n行\n",
    "food_info.columns  #查看数据中的列名\n",
    "food_info.shape    # 查看矩阵数据的维度规模\n",
    "food_info.ndim     # 查看数据的维度\n",
    "food_info.tail(3)  # 查看数据的最后n行超过数据范围会报错\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据的索引和计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "food_info.loc[0]  # 取出第n行数据\n",
    "food_info.loc[2]  #\n",
    "food_info.loc[1:6] # 取出指定行的数据\n",
    "ndb_ccol = food_info[\"NDB_No\"]\n",
    "print(ndb_ccol)   # 通过列名取数据\n",
    "\n",
    "# 通过将列名放置在列表中,来取多列的数据\n",
    "cols_name = [\"Zinc_(mg)\", \"Copper_(mg)\"]\n",
    "cols_2 = food_info[cols_name]  # 取出多行\n",
    "# cols_2\n",
    "\n",
    "# 加减乘除\n",
    "div1000 = food_info[\"Iron_(mg)\"]/1000  # 列除法\n",
    "print(div1000)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(8618, 37)\n"
     ]
    }
   ],
   "source": [
    "# 将列计算后的结果作为新的的属性加入到原矩阵中 \n",
    "# 创建新的属性列, 而后加入属性列\n",
    "#water_energy = food_info[\"Water_(g)\"] * food_info[\"Energ_Kcal\"]\n",
    "water_energy = food_info[\"Water_(g)\"] * food_info[\"Energ_Kcal\"]\n",
    "iron_grams = food_info[\"Iron_(mg)\"] / 1000\n",
    "food_info[\"Iron_(g)\"] = iron_grams  # 将新的计算列加入到原矩阵中\n",
    "print(food_info.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 矩阵的元素列中的最大值 .max 最小值.min 均值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "902"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "max_col = food_info[\"Energ_Kcal\"].max() # 矩阵中的元素列的最大值\n",
    "max_col "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
